package genetic;

public class F3Individual extends Individual {

	public F3Individual() {
		x = new double[3];
	}
	
	public Double f3(){
		double sum = 0;
		for (int i = 0; i < x.length; i++) {
			sum = sum + x[i]*x[i]-10*Math.cos(2*Math.PI*x[i])+10;
		}
		return sum;
	}
	
	//Quando mais proximo de zero, melhor
	@Override
	public Double fitness() {
		return Math.abs(f3());
	}

	@Override
	public void normalize() {
		for (int i = 0; i < x.length;i++) {
			x[i] = Math.max(Math.min(x[i],5.12),-5.12);
		}
	}
	
	@Override
	public String toString() {
		return ((Double)x[0]).toString() + " " + ((Double)x[1]).toString() + " " + ((Double)x[2]).toString() + " " + fitness().toString(); 
	}

}
